﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using LotteryVote.Logic.Exceptions;

namespace LotteryVote.Logic.Web
{
    public class AuthorizePage : BasePage
    {

        protected virtual SystemRole IdentityRole
        {
            get
            {
                return SystemRole.Guest;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            CheckRole();
            CheckState();
            base.OnInit(e);
        }

        protected void CheckState()
        {
            if (CurrentUser.UserInfo.State != UserState.Active)
                Response.Redirect("~/NoPermissions.aspx");
        }
        protected virtual void CheckRole()
        {
            Execute(() =>
            {
                if (!IsLogin)
                    Response.Redirect("Login.aspx?ReturnUrl=" + Request.RawUrl);
                if (CurrentUser.Role > IdentityRole)
                    throw new NoPermissionException("没有访问权限!");
            });
        }

    }
}
